package com.xinchen.aiowaste.ui.fragment

import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import com.blankj.utilcode.util.ActivityUtils
import com.kongqw.network.monitor.enums.NetworkState
import com.maple.common.widget.dialog.CommonDialog
import com.maple.utils.ext.toVisible
import com.maple.utils.util.LogUtils
import com.xinchen.aiowaste.R
import com.xinchen.aiowaste.base.BaseFragment
import com.xinchen.aiowaste.ui.activity.AccountActivity

class SettingFragment : BaseFragment() {

    override fun hasNavController(): Boolean  = true

    override fun hasNetworkState(): Boolean = true
    override fun getLayoutId(): Int = R.layout.fragment_setting

    private var llVersion: LinearLayout? = null
    private var llAbout: LinearLayout? = null

    private var btnLogout: Button? = null

    private val logoutDialog: CommonDialog by lazy {
        CommonDialog(requireContext(),
            title = "退出登录",
            content = "是否确认退出？",
            confirm = "退出",
            cancel = "取消",
            listener = object :CommonDialog.OnClickListener{
            override fun onConfirmClick() {
                super.onConfirmClick()
                ActivityUtils.finishAllActivities()
                onStartActivity(AccountActivity::class.java)
            }
        })
    }
    override fun initView(view: View, savedInstanceState: Bundle?) {
        super.initView(view, savedInstanceState)
        setTitle("系统设置")
        showClockTime()
        onBackClick {
            onFinish()
        }


        llVersion = view.findViewById(R.id.ll_version)
        llAbout = view.findViewById(R.id.ll_about)
        llVersion?.setOnClickListener {
            onOpenVersion()
        }
        llAbout?.setOnClickListener {
            onOpenAbout()
        }
        btnLogout = view.findViewById(R.id.btn_logout)
        btnLogout?.setOnClickListener {
            logoutDialog.show()
        }
    }
    override fun initData(savedInstanceState: Bundle?) {

    }

    private fun onOpenVersion() {
        navController?.navigate(R.id.action_settingFragment_to_versionFragment)
    }
    private fun onOpenAbout() {
        navController?.navigate(R.id.action_settingFragment_to_aboutFragment)
    }
}